package com.xique.park.controller.auto;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.xique.common.core.domain.R;
import com.xique.park.api.request.RemoteReceiveCouponRequest;
import com.xique.park.service.biz.service.ICouponBizService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.xique.common.log.annotation.Log;
import com.xique.common.log.enums.BusinessType;
import com.xique.common.security.annotation.PreAuthorize;
import com.xique.park.bean.domain.ParkCouponPp;
import com.xique.park.service.service.IParkCouponPpService;
import com.xique.common.core.web.controller.BaseController;
import com.xique.common.core.web.domain.AjaxResult;
import com.xique.common.core.utils.poi.ExcelUtil;
import com.xique.common.core.web.page.TableDataInfo;

/**
 * 商户优惠券ppController
 *
 * @author xique
 * @date 2021-12-09
 */
@RestController
@RequestMapping("/couponPp")
public class ParkCouponPpController extends BaseController
{
    @Autowired
    private IParkCouponPpService parkCouponPpService;

    @Autowired
    private ICouponBizService couponBizService;

    /**
     * 查询商户优惠券pp列表
     */
    @PreAuthorize(hasPermi = "park:pp:list")
    @GetMapping("/list")
    public TableDataInfo list(ParkCouponPp parkCouponPp)
    {
        startPage();
        List<ParkCouponPp> list = parkCouponPpService.selectParkCouponPpList(parkCouponPp);
        return getDataTable(list);
    }

    /**
     * 导出商户优惠券pp列表
     */
    @PreAuthorize(hasPermi = "park:pp:export")
    @Log(title = "商户优惠券pp", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ParkCouponPp parkCouponPp) throws IOException
    {
        List<ParkCouponPp> list = parkCouponPpService.selectParkCouponPpList(parkCouponPp);
        ExcelUtil<ParkCouponPp> util = new ExcelUtil<ParkCouponPp>(ParkCouponPp.class);
        util.exportExcel(response, list, "商户优惠券pp数据");
    }

    /**
     * 获取商户优惠券pp详细信息
     */
    @PreAuthorize(hasPermi = "park:pp:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(parkCouponPpService.selectParkCouponPpById(id));
    }

    /**
     * 新增商户优惠券pp
     */
    @PreAuthorize(hasPermi = "park:pp:add")
    @Log(title = "商户优惠券pp", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ParkCouponPp parkCouponPp)
    {
        return toAjax(parkCouponPpService.insertParkCouponPp(parkCouponPp));
    }

    /**
     * 修改商户优惠券pp
     */
    @PreAuthorize(hasPermi = "park:pp:edit")
    @Log(title = "商户优惠券pp", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ParkCouponPp parkCouponPp)
    {
        return toAjax(parkCouponPpService.updateParkCouponPp(parkCouponPp));
    }

    /**
     * 删除商户优惠券pp
     */
    @PreAuthorize(hasPermi = "park:pp:remove")
    @Log(title = "商户优惠券pp", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(parkCouponPpService.deleteParkCouponPpByIds(ids));
    }

    /**
     * 领取优惠券
     * @author shd
     * @date 2022/1/12 14:37
     * @param request
     * @return com.xique.common.core.domain.R<java.lang.Boolean>
     */
    @PostMapping("/receiveCoupon")
    R<Boolean> receiveCoupon(@RequestBody RemoteReceiveCouponRequest request) {
        return couponBizService.receiveCoupon(request);
    }
}
